$(document).ready(function () {
    layui.use([ 'table', 'element', 'laydate','carousel'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var element = layui.element;
        var laydate = layui.laydate;
        var carousel = layui.carousel;

        //建造实例
        carousel.render({
          elem: '#carousel'
          ,width: '100%' //设置容器宽度
          ,arrow: 'always' //始终显示箭头
          //,anim: 'updown' //切换动画方式
        });

        //获取应用数据信息集合JSON
       /* $.ajax({
            url: window.ViewContextPath+"/modules/dashboard/data/yyrk_data.json",
            dataType: "json",
            type: "get",
            success: function (data) {
                $(data.appList).each(function () {
                    var appInfo = $(this);
                    //应用数据过滤
                    $("div").filter(".app_div_cls").each(function () {
                        var appName = $(this).children("p").text();
                        if (appInfo[0].appName == appName) {
                            if(appInfo[0].enabled){
                                $(this).click(function () {
                                    layer.msg("即将打开子系统：" + appName, {anim: 0}, function () {
                                        window.open("http://192.168.135.63:8080/centit-ip");
                                        // layer.open({
                                        //     type: 2,//iframe
                                        //     title: appName,
                                        //     content: 'http://127.0.0.1:8080/centit-ip/modules/dashboard/homepage.html', //iframe存在跨域问题
                                        //     maxmin: true,
                                        //     success: function (layero, index) {
                                        //         layer.full(index);//全屏显示
                                        //     }
                                        // });
                                    });
                                });
                            }else{
                                $(this).addClass("app_disabled");
                                $(this).click(function(){
                                    layer.msg("对不起，" + appName + "暂时不可用");
                                });
                            }
                        }
                    })
                });
            }
        });*/
        table.on('tool(scheduleFilter)', function(obj){
            var data = obj.data;
            var value = "";
            if(obj.event === 'setSign1'){
            	value = data.week1
            }
            if(obj.event === 'setSign2'){
            	value = data.week2
            }
            if(obj.event === 'setSign3'){
            	value = data.week3
            }
            if(obj.event === 'setSign4'){
            	value = data.week4
            }
            if(obj.event === 'setSign5'){
            	value = data.week5
            }
            if(typeof(value)!="undefined"){
            	layer.tips(
            		"<font color='black'>"+value+"</font>", 
            		this, 
            		{tips: [1, '#ffffff'],
            		time: 2000
            	});
            }
          });

    });
})

//会议安排数据渲染
function dataFilter(res, curr, count) {
	var i = 0;
    $("table[class='layui-table']").find("td").each(function () {
    	var dataField = $(this).attr("data-field");
        if ($(this).text() != ""&&dataField!="roomNo") {
            var json=eval($(this).text());
            var am=false;
            var pm=false;
            $.each(json,function(i,item){
                if(item.amOrpmStr=='am'){
                    am=true;
                }
                if(item.amOrpmStr=='pm'){
                    pm=true;
                }
            });
        	$(this).append("<input type='hidden' value='"+$(this).text()+"'>");
            $(this).addClass("in_use_cls");
            $(this).attr("index",i);
            //$(this).find("div").html("<font color='white'>在用</font>");
            var tableStr="<table class='duijiao'>\n" +
                "<tr>" +
                "<th >" +
                "<div class=\"out\" style=\"font-size:7px\">" ;
                if(am==true){
                    tableStr+="<b onmouseover='am("+$(this).text()+")' onmouseout='hideDiv()' >上午</b>";
                }else{
                    tableStr+="<b class='ampmn'>-</b>";
                }
            if(pm==true){
                tableStr+="<em onmouseover='pm("+$(this).text()+")' onmouseout='hideDiv()'>下午</em>";
            }else{
                tableStr+="<em class='ampmn'>-</em>";
            }
            tableStr+= "</div>" +
                "</th>" +
                "</tr>" +
                "</table>";
            $(this).find("div").html(tableStr);
            i++;
        }
        if ($(this).text() == "") {
        	$(this).find("div").html("<font color='black'>-</font>");
        }
    });
}



var curWwwPath=window.document.location.href;
var pathName=window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);
var localhostPaht=curWwwPath.substring(0,pos);
$(document).ready(function(){
	 var RURL=window.nginxpath+"cas/login?service="+window.nginxpath+"apprFlow/login/cas";
    registermodel(RURL);
    
});
function optIndex(module,detailId,openid){
    /*var modules=['doctrans','PARTYBUILD','MEET','XMGL','random','all','CONTACTS','ARCHIVE','OA','apprFlow','centitIp'];
    var result = $.inArray(module, modules);*/
        var index = layer.load(1, {
            shade: [0.6,'#fff'] //0.1透明度的白色背景
        });
       
        if (module == 'CONTACTS'){
            openDiv("1200px","800px",window.ViewContextPath + "modules/dashboard/dashboardtxl.jsp","通讯录");
            layer.close(index);
            // window.open(localhostPaht+"/centit-ip/modules/dashboard/dashboardtxl.jsp");
        }else {
            if(module=="doctrans"||module=="OA" || module=='PERSONNEL'|| module == 'SPFW' || module=='OPTMNG'||module=='EXAMINATION'){
                var RURL=window.nginxpath+"cas/login?service="+window.nginxpath+"apprFlow/login/cas";
                registermodel(RURL);
            }
            var RURL=window.nginxpath+"cas/login?service="+window.nginxpath+module.toLowerCase()+"/login/cas";
            if(module!='OPTMNG'&&module!='EXAMINATION'){
                registermodel(RURL);
            }
            if(module=='EXAMINATION'){//特殊判断人事考核
                registermodel(window.nginxpath+"cas/login?service="+window.nginxpath+'PERSONNEL'.toLowerCase()+"/login/cas");
            }
            var url=window.ViewContextPath+"system/layui/dashWindow?module="+module;
            if(typeof(detailId)!="undefined"&&detailId!=""&&detailId!="undefined"){
               url+="&detailId="+detailId;
            }
            if(typeof(openid)!="undefined"&&openid!=""&&openid!="undefined"){
                url+="&openid="+openid;
            }
            window.location.href=url;
        }

}

//编辑常用功能
function editAlwaysModel() {
//    openDiv("800px","600px",window.ViewContextPath + "system/always/alwaysmodel/searchModels","常用功能编辑");
}

//更多日程安排
function moreSchedule() {
    var url=window.nginxpath+"oa/modules/doc/schedule/schedule.jsp?flag=T";
  openDiv("1220px","600px",url,"厅局级领导日程活动");
}

//更多会议安排
function moreMeet() {
	openDiv("1250px","600px",window.nginxpath + "/meet/modules/meet/hyglhyrc/hyglhyrc-master.jsp","会议安排");
}

//更多待办事项
function moreTodoitems() {
    openDiv("1020px","600px",window.ViewContextPath + "system/todoItem/listTodoItem","待办事项");
}
//数字点击待办事项
function clickTodoitems(item,title) {
    openDiv("1020px","600px",window.ViewContextPath + "system/todoItem/listTodoItem?item="+item,title);
}
//更多消息提醒
function moreMessageInfo(dataType) {
    openDiv("1000px","600px",window.ViewContextPath + "system/messageInfo/listMessageInfo?dataType="+dataType,"消息提醒");
}
//更多通知公告
function moreTzggInfo(datatype) {
    /*openDiv("1000px","600px",window.ViewContextPath + "system/messageInfo/listMessageInfo?dataType="+dataType,"通知公告");*/
    window.open(window.ViewContextPath + "modules/dashboard/messageinfo/public.jsp?datatype="+datatype);
}
//拥有tab页的更多
function moreTzggInfoMore(id) {
    var tabName=$(id).parent().parent().find('.layui-this').html();
    var datatype="";

    if(tabName=="学习心得"){
        datatype="3";
    }else if(tabName=="培训教材"){
        datatype="4";
    }else if(tabName=="出国公示"){
        datatype="7";
    }else if(tabName=="表彰公示"){
        datatype="8";
    }else if(tabName=="考核公示"){
        datatype="9";
    }
    /*openDiv("1000px","600px",window.ViewContextPath + "system/messageInfo/listMessageInfo?dataType="+dataType,"通知公告");*/
    window.open(window.ViewContextPath + "modules/dashboard/messageinfo/public.jsp?datatype="+datatype);
}
//常用功能更多展示
function moreAlwaysModel() {
//    openDiv("1000px","600px",window.ViewContextPath + "system/always/alwaysmodel/listAlwaysMod?type=2","常用功能");
}

//页面点击代办详情
function moreAgency(url,module) {
    var index = layer.load(1, {
        shade: [0.6,'#fff'] //0.1透明度的白色背景
        ,success:function () {
            //待办默认都需注册流程系统
            var RURL=window.nginxpath+"cas/login?service="+window.nginxpath+"apprFlow/login/cas";
            registermodel(RURL);
            RURL=window.nginxpath+"cas/login?service="+window.nginxpath+module.toLowerCase()+"/login/cas";
            openDiv("1000px","600px",window.nginxpath +url,"待办详情");

        }
    });
    layer.close(index);
}
window.onload = function(){
    //初始化常用功能模块
//    $.ajax({
//        type : "GET",
//        url : window.ViewContextPath + 'system/always/alwaysmodel/listAlwaysMod?type=1',
//        async : false,
//        dataType : "json",
//        success : function(data) {
//            var cygnShow = $("#cygnShow");
//            try{
//            if (data) {
//                data = data.data;
//                var menusOwnerHidVal = $("#menusOwnerHid").val();
//                var wld = $("#wld").val();
//                var n = 15;
//                if (wld == "true") {
//                    n = data.objList.length;
//                }
//                for (var i = 0; i < data.objList.length && i < n; i++) {
//                    if (null != data.objList[i]) {
//                        var modelClass = data.objList[i].modelclass;
//                        if ("CONTACTS" == data.objList[i].modelcode || ((typeof(modelClass) == "undefined" || modelClass == "undefined" || modelClass == "") && menusOwnerHidVal.indexOf(data.objList[i].modelcode) != -1 || menusOwnerHidVal.indexOf(modelClass) != -1)) {
//                            cygnShow.append("<div class = 'cygn_module_cls' >" +
//                                "<img src = '" + window.ViewContextPath + data.objList[i].modelimgurl + "'" +
//                                " alt = " + data.objList[i].modelname + " onclick=optIndex('" + data.objList[i].modelcode + "','" + data.objList[i].modelclass + "')" +
//                                " /><p >" + data.objList[i].modelname + "</p ></div >");
//                        } else {
//                            var modelingurlArr = data.objList[i].modelimgurl.split(".");
//                            cygnShow.append("<div class = 'cygn_module_cls app_disabled' >" +
//                                "<img src = '" + window.ViewContextPath + modelingurlArr[0] + "2." + modelingurlArr[1] + "'" +
//                                " alt = " + data.objList[i].modelname +
//                                " /><p >" + data.objList[i].modelname + "</p ></div >");
//                        }
//
//                    }
//                }
//
//            }
//        }catch(E){
//
//        }
//            cygnShow.append("<div class = 'cygn_module_cls' >" +
//                "<img src = '"+window.ViewContextPath+"/modules/dashboard/image/more.png"+"'"+
//                " alt = "+"编辑" +" onclick='editAlwaysModel()'"+
//                " /><p >"+"编辑"+"</p ></div >");
//        }
//    });
}

function am(str) {
    var content="<ul class='layer_notice'>";
    $.each(str,function(i,item){
        if(item.amOrpmStr=='am'){
            content+="<li><div class='liNum'>"+(i+1)+".</div>"+"<div class='lititle'>"+item.hyzt.replace(/^\s\s*/, '').replace(/\s\s*$/, '')+"</div><div class='lidate'>"+item.hysj+"</div></li>";
        }
    });
    content+="</ul>";
    $("#rcInfodiv").html(content);
    var left = event.clientX;
    var top = event.clientY;
    $("#rcInfodiv").css("left", left+20);
    $("#rcInfodiv").css("top", top);
    $("#rcInfodiv").show();

}
function pm(str) {
    var content="<ul class='layer_notice'>";
    $.each(str,function(i,item){
        if(item.amOrpmStr=='pm'){
            content+="<li><div class='liNum'>"+(i+1)+".</div>"+"<div class='lititle'>"+item.hyzt.replace(/^\s\s*/, '').replace(/\s\s*$/, '')+"</div><div class='lidate'>"+item.hysj+"</div></li>";
        }
    });
    content+="</ul>";
    $("#rcInfodiv").html(content);
    var left = event.clientX;
    var top = event.clientY;
    $("#rcInfodiv").css("left", left+20);
    $("#rcInfodiv").css("top", top);
    $("#rcInfodiv").show();
}
function hideDiv(){
    $("#rcInfodiv").hide();
}
function addFavorite2(){
    var title = document.title;
    var URL = document.URL;
    try{window.external.addFavorite(URL, title);}
    catch (e)
    {
        try{window.sidebar.addPanel(title, URL, "");}
        catch (e){alert("加入收藏失败，请使用Ctrl+D进行添加");}
    }


}
function edtiuserinfo(){
    var index = layui.layer.open({
        title : "编辑用户信息",
        type : 2,
        offset: '100px',
        skin:'layui-layer-molv',
        content : window.ViewContextPath+"system/layui/goEdit",
        area: ["700px","500px"],
        success : function(layero, index){

        }
    })
}